﻿using Desktop.Library;
using System.Collections.Generic;
using System;
using System.Windows;
using System.Windows.Controls;

namespace Desktop.Controls
{
    /// <summary>
    /// An application is made up of ribbons.  Each ribbon
    /// knows how to open a set of workspaces.
    /// </summary>
    public class Ribbon : TabItem
    {
        #region Constructors

        public Ribbon()
        {
            Style = FindResource("RibbonStyle") as Style;
            Application = null;
            Workspaces = new Dictionary<string, WorkspaceDescriptor>();
        }

        public Ribbon(Application app)
            : this()
        {
            Application = app;
        }

        #endregion

        #region Properties

        private Application Application { get; set; }
        private Dictionary<string, WorkspaceDescriptor> Workspaces { get; set; }

        #endregion

        #region Methods

        protected void AddWorkspace(string name, bool isCloseable, params Type[] activities)
        {
            if (Workspaces.ContainsKey(name))
            {
                Workspaces.Remove(name);
            }
            Workspaces.Add(name, new WorkspaceDescriptor(name, isCloseable, activities));
        }

        public Workspace OpenWorkspace(string workspaceName)
        {
            if (!Workspaces.ContainsKey(workspaceName))
            {
                throw new Exception(string.Format("This ribbon doesn't now how to open '{0}'.", workspaceName));
            }
            return Workspaces[workspaceName].Open(Application);
        }

        #endregion
    }
}